package scu.maqiang.optimization;

import scu.maqiang.mesh.MatrixFunc;
import scu.maqiang.mesh.ScalarFunc;
import scu.maqiang.mesh.VectorFunc;
import scu.maqiang.numeric.NLOPT;

public class RosenbrockFunctionTest {
    public static ScalarFunc RosenbrockFunc = (x, label, param) -> 100 * (x[0] * x[0] - x[1]) * (x[0] * x[0] - x[1]) + (x[0] - 1) * (x[0] - 1);
    public static VectorFunc d_RosenbrockFunc = (x, label, param) -> {
        double[] grad = new double[2];
        grad[0] = 400 * x[0] * (x[0] * x[0] - x[1]) + 2 * (x[0] - 1);
        grad[1] = -200 * (x[0] * x[0] - x[1]);
        return grad;
    };

    public static MatrixFunc hess_RosenbrockFunc = (x, label, param) -> {
        double[][] hess = new double[2][2];
        hess[0][0] = 1200 * x[0] * x[0] - 400 * x[1] + 2.0;
        hess[0][1] = -400 * x[0];
        hess[1][0] = -400 * x[0];
        hess[1][1] = 200;
        return hess;
    };
    public static void main(String[] args) {
        double[] x0 = new double[] {0.5, 1.0};
//        double[] x = NLOPT.SteepestDescent(RosenbrockFunc, d_RosenbrockFunc, null, x0, NLOPT.SearchStep.Armijo, null, "SD_Armijo.dat");
    }
}
